<?php
    session_start();
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oid = $_REQUEST['oid'];
    $usuario = $_SESSION['usuario'];
    $pq = $_REQUEST['pq'];
    
    if($usuario == ""){
            print_r(json_encode(array('n'=>1)));
   }else{
       $count = "select count(*)as n from segtranslado where hcnsolexa='".$oid."'";
       $res = $con->query($count);
       
        while($res2 = mssql_fetch_array($res)){
         $n = $res2['n'];
        } 
        if($n == 0){
            $insert= "insert into segtranslado (hcnsolexa,traisladono,trfechano,usu_oidno)
                      values('".$oid."','1',GETDATE(),'".$_SESSION['usuario']."')";
            $con->query($insert);
        }else{
            $update = "update segtranslado
                        set traisladono = '1',
                        trfechano = GETDATE(),
                        usu_oidno = '".$_SESSION['usuario']."',
                        traisladosi = '',
                        trtipoaislami = '',
                        trfechapoais = '',
                        usu_oidpoais = ''
                        where hcnsolexa = '".$oid."'";
            $con->query($update);
        }
        print_r(json_encode(array('n'=>2)));
        
        $Existe = "select count(*) as E from segimagenes where hcnsolexa = '".$oid."'";
        $resp = $con ->query($Existe);

        while($resp2 = mssql_fetch_array($resp)){
            $E = $resp2['E'];
        }
        if($E == 0){
            $insertar = "insert into segimagenes (hcnsolexa,solcita,fecsolcita,usu_oidsc)values('".$oid."','1',GETDATE(),'".$_SESSION['usuario']."')";
            $con ->query($insertar);
        }else{
            $Editar = "update segimagenes
                       set solcita =  '1',
                       fecsolcita = GETDATE(),
                       usu_oidsc = '".$_SESSION['usuario']."'
                       where hcnsolexa = '".$oid."'";
            $con ->query($Editar);
        }
   }  
    $con->cerrarConexion();
    
 
?>